package com.ice.body.business.controller;

import com.github.pagehelper.PageHelper;
import com.ice.base.controller.BaseController;
import com.ice.base.model.SysLoginModel;
import com.ice.base.result.AjaxResult;
import com.ice.base.result.ResponseResult;
import com.ice.base.util.BaseUtil;
import com.ice.body.business.model.WarningModel;
import com.ice.body.business.service.WarningService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2022-04-11
 * Time: 02:09
 */
@Slf4j
@RestController
@ApiIgnore(value = "临期预警")
public class WarningController extends BaseController{
    //---------------------------临期预警-----------------------start
    @Resource
    private WarningService warningService;
    


    @ApiOperation(value = "临期预警-删除")
    @PostMapping("/api/warning/deleteById")
    public AjaxResult<WarningModel> deleteById_TemporaryWarning(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
            Integer count = warningService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "预警-改为已处理")
    @PostMapping("/api/warn/done")
    public AjaxResult<WarningModel> done(String id) {
        log.info("处理预警信息id:"+id);
        AjaxResult r = ResponseResult.success();
        try{
            Integer count = warningService.done(id);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();
        }
        return r;
    }


  /*  @ApiOperation(value = "临期预警-查询一个")
    @PostMapping("/api/warning/selectById")
    public Result<WarningModel> selectById_TemporaryWarning(@RequestParam("id") String id) {
        Result r = ResponseResult.success();
        try{
           WarningModel model = warningService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }*/



    @ApiOperation(value = "临期预警-测试查询")
    @PostMapping("/api/warn/getCount")
    public AjaxResult<T> getCount( ){

        AjaxResult r = ResponseResult.success();
        ArrayList list;
        SysLoginModel currLoginModel = BaseUtil.getCurrLoginModel();
        if(!"admin".equals(currLoginModel.getUserName())){

        }
        try{
            HashMap data = new HashMap(2);
            data.put("temCount",200);
            data.put("expireCount",123);
        r.setData(data);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "临期预警-查询分页")
    @PostMapping("/api/warn/selectTemporary")
    public AjaxResult<WarningModel> selectTemporary(@RequestParam(name = "pageSize") Integer pageSize,
                                                    @RequestParam(name = "pageNum") Integer pageNum,
                                                    WarningModel model){
        model.setWarnType(1);
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        SysLoginModel currLoginModel = BaseUtil.getCurrLoginModel();
        if(!"admin".equals(currLoginModel.getUserName())){

        }
        try{
            PageHelper.startPage(pageNum, pageSize);
            list = warningService.selectListByModel(model);
            getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();
        }
        return r;
    }


    @ApiOperation(value = "过期预警-查询分页")
    @PostMapping("/api/warn/selectExpire")
    public AjaxResult<WarningModel> selectExpire(@RequestParam(name = "pageSize") Integer pageSize,
                                                 @RequestParam(name = "pageNum") Integer pageNum,
                                                 WarningModel model){
        model.setWarnType(2);
        AjaxResult r = ResponseResult.success();
        ArrayList list;
        SysLoginModel currLoginModel = BaseUtil.getCurrLoginModel();
        if(!"admin".equals(currLoginModel.getUserName())){
           // model.setCompanyId(currLoginModel.getCompanyId());
        }
        try{
            PageHelper.startPage(pageNum, pageSize);
            list = warningService.selectListByModel(model);
            getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();
        }
        return r;
    }
    //---------------------------临期预警-----------------------end
}
